﻿using Model.CustomDataType;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace Model
{
    public class Utils
    {
        public static int convertSexEnumToInt(Model.Person.Sex sex)
        {
            if (sex == null)
                return 0;
            return (int) sex;
        }
        public static Model.Person.Sex convertIntToSexEnum(int sex)
        {
            return sex == 0 ? Model.Person.Sex.NONE : (sex == 1 ? Model.Person.Sex.MALE : Model.Person.Sex.FEMALE);
        }
        /// <summary>
        /// Convert a String to CMDatetime
        /// </summary>
        /// <param name="src">The CMDatime formatted string: dd/mm/yyyy hh:mm:ss</param>
        /// <returns>The CMDatetime converted from string</returns>
        public static CMDateTime convertDateTimeToCMDateTime(DateTime dt)
        {
            if(dt==null)
            {
                return new CMDateTime();
            }
            return new CMDateTime(dt.Day, dt.Month, dt.Year, dt.Hour, dt.Minute, dt.Second);
        }

        public static DateTime convertCMDateTimeToDateTime(CMDateTime myDob)
        {
            if(myDob==null)
            {
                myDob = new CMDateTime();
            }
            return new DateTime(myDob.getYear(), myDob.getMonth(), myDob.getDay(),
                myDob.getHour(), myDob.getMinute(), myDob.getSecond());
        }

        //public static Type[] convertDataTableToArray(DataTable dataTable, string type)
        //{
        //    Type t = Type.GetType(type, false, true);


        //}

    }
}
